<?php

class Widget_ProductCart extends WP_Widget {

	function Widget_ProductCart() {
		$widget_ops = array( 'classname' => 'widget_product_cart', 'description' => __( "Giỏ hàng" ) );
		parent::WP_Widget( false, __( 'Giỏ hàng', 'woothemes' ), $widget_ops );
	}

	function widget( $args, $instance ) {
		extract( $args );

		$title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Giỏ hàng' ) : $instance['title'], $instance, $this->id_base);
		echo $before_widget;
		if ( $title )
			echo $before_title . $title . $after_title;
           echo "<div class='cart'>
                <p><a href='".get_permalink(get_page_id("gio-hang"))."'><span class='total-cart'>".get_total_cart()."</span> sản phẩm</a></p>
            </div>";
           
		echo $after_widget;
        ?>
       <script type='text/javascript'>
        /* <![CDATA[ */
        	jQuery(function ( $ ){
        	   $(".btn-dathang").bind("click",function(){
        	       $("#<?=$widget_id?> .total-cart").addClass("ajax-load");
        	       var link = "<?=wp_nonce_url(admin_url("admin-ajax.php?action=total-cart", "total-cart"))?>";
                   var loading = $("<div class='loading' />").prependTo($(".total-cart"));
                   setInterval(function(){
                        loading.remove();
                   },5000);
        	   })
        	});
        /* ]]> */
        </script>
       <?php 
           
	}

	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		return $instance;
	}

	function form( $instance ) {
		//Defaults
		$instance = wp_parse_args( (array) $instance, array( 'title' => '') );
		$title = esc_attr( $instance['title'] );
?>
		<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:' ); ?></label>
		<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>
<?php
	}
    
    

}

register_widget( 'Widget_ProductCart' );


?>